package WEB.servlet.actions;

import db.dao.IntakeDao;
import db.exceptions.IntakeDaoException;
import db.factory.IntakeDaoFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * User: Vanil
 * Date: 20.12.2010
 * Time: 17:48:32
 */
public class DelIntake implements Action {
    public String perform(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            int num = new Integer(request.getParameter("idIntake"));
            IntakeDao dao = IntakeDaoFactory.create();
            dao.delete(num);
            return "/show.do";
        } catch (IntakeDaoException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (NumberFormatException e)
        {
            request.getSession().setAttribute("errorMessage","Invalid id of intake");
        }
        return "/error.jsp";
    }
}
